<html>
<head><meta charset="utf-8"><title>Proc macro expansion · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html">Proc macro expansion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233971916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233971916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233971916">(Apr 10 2021 at 17:19)</a>:</h4>
<p>Is it expected that for a proc macro with this call <code>bevy_ecs_macros::all_tuples! {impl_tuple_fetch, 0, 1, F, A }</code>, that the proc macro receives the following TokenStream?</p>
<div class="codehilite"><pre><span></span><code>TokenStream [Group { delimiter: Brace, stream: TokenStream [Ident { ident: &quot;impl_tuple_fetch&quot;, span: 4294967295 }, Punct { ch: &#39;,&#39;, spacing: Alone, span: 4294967295 }, Literal { kind: , symbol: &quot;0&quot;, suffix: None, span: 3 }, Punct { ch: &#39;,&#39;, spacing: Alone, span: 4294967295 }, Literal { kind: , symbol: &quot;1&quot;, suffix: None, span: 5 }, Punct { ch: &#39;,&#39;, spacing: Alone, span: 4294967295 }, Ident { ident: &quot;F&quot;, span: 4294967295 }, Punct { ch: &#39;,&#39;, spacing: Alone, span: 4294967295 }, Ident { ident: &quot;A&quot;, span: 4294967295 }], span: 0 }]
</code></pre></div>
<p>Note the delimiter grouping at the start</p>



<a name="233972009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233972009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233972009">(Apr 10 2021 at 17:20)</a>:</h4>
<p>Been trying out bevy wondering why a lot of inference doesnt work and it seems that this proc macro doesnt expand(it emits <code>compile_error</code> which we also dont emit a diagnostic for) saying it expects an ident.</p>



<a name="233972051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233972051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233972051">(Apr 10 2021 at 17:21)</a>:</h4>
<p>hmm, do we strip the outer group when you invoke it with <code>();</code>?</p>



<a name="233972120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233972120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233972120">(Apr 10 2021 at 17:22)</a>:</h4>
<p>Nope, still contains the delimiters</p>



<a name="233972177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233972177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233972177">(Apr 10 2021 at 17:22)</a>:</h4>
<p>Also when called with <code>[];</code></p>



<a name="233972290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233972290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233972290">(Apr 10 2021 at 17:24)</a>:</h4>
<p>Wouldn't mind looking into this some more but in that case I need some pointers where to look since I'm not into macro stuff in RA</p>



<a name="233973748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233973748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233973748">(Apr 10 2021 at 17:46)</a>:</h4>
<p>Okay I think the problem is in this PR <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8443">https://github.com/rust-analyzer/rust-analyzer/pull/8443</a>, commit prior to this works fine</p>



<a name="233973884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233973884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233973884">(Apr 10 2021 at 17:48)</a>:</h4>
<p>oh, seems like the old code removed the outer group, but that's not documented anywhere</p>



<a name="233973896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233973896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233973896">(Apr 10 2021 at 17:48)</a>:</h4>
<p>"remove derives" is not something that should happen for fn-like macros, but we do need to do that part</p>



<a name="233974356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974356">(Apr 10 2021 at 17:57)</a>:</h4>
<p><code>TokenBuffer</code> stripped the outer grouping before then I suppose?</p>



<a name="233974598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974598">(Apr 10 2021 at 18:00)</a>:</h4>
<p>yeah: <code>TokenBuffer::from_tokens(&amp;tt.token_trees);</code></p>



<a name="233974608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974608">(Apr 10 2021 at 18:01)</a>:</h4>
<p>disposes <code>tt.delimiter</code></p>



<a name="233974635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974635">(Apr 10 2021 at 18:01)</a>:</h4>
<p>and <code>let mut result = tt::Subtree::default();</code> creates a subtree without delimiter</p>



<a name="233974645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974645">(Apr 10 2021 at 18:01)</a>:</h4>
<p>I'm thinking we might want to revert that PR because it's also otherwise broken</p>



<a name="233974839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974839">(Apr 10 2021 at 18:04)</a>:</h4>
<p>does this make github unhappy or is that just me? <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8443/revert">https://github.com/rust-analyzer/rust-analyzer/pull/8443/revert</a></p>



<a name="233974848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974848">(Apr 10 2021 at 18:04)</a>:</h4>
<p>Unhappy in what sense?</p>



<a name="233974865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974865">(Apr 10 2021 at 18:05)</a>:</h4>
<p>opening that just redirects me to the PR without the <code>revert</code> part</p>



<a name="233974889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233974889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233974889">(Apr 10 2021 at 18:05)</a>:</h4>
<p>Oh clicking the revert button server errors, I guess that's what you mean <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="233975162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233975162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233975162">(Apr 10 2021 at 18:10)</a>:</h4>
<p>ah, yeah</p>



<a name="233977640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Proc%20macro%20expansion/near/233977640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Proc.20macro.20expansion.html#233977640">(Apr 10 2021 at 18:46)</a>:</h4>
<p>reverted it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>